package com.itheima.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.mapper.SmsCouponProductCategoryRelationMapper;
import com.itheima.pojo.SmsCouponProductCategoryRelation;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class SmsCouponProductCategoryRelationApiImpl implements SmsCouponProductCategoryRelationApi{
    @Autowired
    private SmsCouponProductCategoryRelationMapper smsCouponProductCategoryRelationMapper;
    /**
     * 优惠券绑定的商品分类添加
     * @param productCategoryRelationList
     */
    @Override
    public void create(List<SmsCouponProductCategoryRelation> productCategoryRelationList) {
        for (SmsCouponProductCategoryRelation smsCouponProductCategoryRelation : productCategoryRelationList) {
            smsCouponProductCategoryRelationMapper.insert(smsCouponProductCategoryRelation);
        }
    }

    /**
     * 根据couponId删除优惠券关联信息
     * @param couponId
     */
    @Override
    public void deleteByCouponId(Integer couponId) {
        LambdaQueryWrapper<SmsCouponProductCategoryRelation> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(SmsCouponProductCategoryRelation::getCouponId,couponId);
        smsCouponProductCategoryRelationMapper.delete(wrapper);
    }

    /**
     * 修改
     * @param smsCouponProductCategoryRelation
     */
    @Override
    public void updateById(SmsCouponProductCategoryRelation smsCouponProductCategoryRelation) {
        smsCouponProductCategoryRelationMapper.updateById(smsCouponProductCategoryRelation);
    }

    /**
     * 获取优惠券信息
     * @param couponId
     * @return
     */
    @Override
    public List<SmsCouponProductCategoryRelation> getSmsCouponById(Integer couponId) {
        LambdaQueryWrapper<SmsCouponProductCategoryRelation> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(SmsCouponProductCategoryRelation::getCouponId,couponId);
        return smsCouponProductCategoryRelationMapper.selectList(wrapper);
    }
}
